<template>
  <div
    class="w100 h100"
    :class="item?.vModel"
  >
    <el-radio-group
      v-bind="{ ...item }"
      style="width: 100%"
    >
      <VueDraggable
        v-model="item!.config.options"
        :animation="150"
        handle=".handle"
        class="w100"
      >
        <template
          v-for="(option, index) in getOptions()"
          :key="option.value"
        >
          <div
            class="radio-item block"
            :class="getOptionClass(option)"
          >
            <el-icon
              size="16"
              v-if="!disabledOperation"
              class="sort-icon handle cursor-pointer"
            >
              <TablerGripVertical />
            </el-icon>
            <el-radio
              :disabled="option.quotaSetting"
              :value="option.value"
              @click.prevent="handleClick(option)"
            >
              <div
                :id="item?.vModel + '-' + option.value"
                class="editor"
                v-html="option.label"
              ></div>
            </el-radio>
            <el-icon
              size="16"
              v-if="!disabledOperation"
              class="sort-icon mr10 cursor-pointer"
              @click="deleteOption(index)"
            >
              <TablerTrash />
            </el-icon>
          </div>
        </template>
      </VueDraggable>
    </el-radio-group>
    <option-operate
      :item="item"
      v-if="activeData?.vModel === item?.vModel && !disabledOperation"
    />
  </div>
</template>

<script setup name="TRadioGroup" lang="ts">
import { onMounted } from "vue";
import { formEmits, formItemProps, useFormItem } from "@/views/formgen/components/FormItem/hooks/useFormItemHook";
import OptionOperate from "@/views/formgen/components/FormDesign/FormItem/components/OptionOperate.vue";
import { VueDraggable } from "vue-draggable-plus";

import TablerGripVertical from "~icons/tabler/grip-vertical";
import TablerTrash from "~icons/tabler/trash";
import { useFormOption } from "@/views/formgen/components/FormDesign/FormItem/hooks/useFormOption";
import { formDesign } from "@/views/formgen/components/FormDesign/hooks/useFormDesign";

const props = defineProps({
  ...formItemProps,
  models: {
    type: Object,
    default: () => {}
  }
});

const { activeData } = formDesign;

const emits = defineEmits([...formEmits, "next"]);

const { getOptions } = useFormItem(props, emits);

const { deleteOption, disabledOperation } = useFormOption(props);

onMounted(() => {});

const getOptionClass = (option: any) => {
  return [];
};

const handleClick = (option: any) => {};
</script>

<style lang="scss" scoped>
.el-radio {
  height: auto;
  padding: 5px 2px;
  line-height: 25px !important;
}

:deep(.el-radio) {
  display: flex;
  border-radius: 8px;
  border: transparent solid 1px;

  .el-radio__input {
    line-height: 32px !important;
  }

  .el-radio__label {
    line-height: 28px !important;
  }
}

.block {
  width: 100%;
  flex-direction: column;

  .el-radio {
    width: 90%;
  }

  .other-input {
    margin-top: 10px;
  }
}

.inline-block {
  display: inline-block;
  margin-right: 10px;
  vertical-align: top;

  .el-radio {
    width: 100%;
  }

  .other-input {
    margin-top: 10px;
  }
}

.inline-block.radio-item {
  min-width: 156px;
}

.el-radio:hover {
  border: var(--el-border-color) dashed 1px;
}

.radio-item {
  display: flex;
  align-content: center;
  align-items: center;
  flex-direction: row;

  .sort-icon {
    visibility: hidden;
  }

  &:hover {
    .sort-icon {
      visibility: visible;
    }
  }

  .vote-wrap {
    padding: 5px 10px;
  }

  .vote-wrap:empty {
    padding: 0;
  }

  .other-input {
    margin-top: 0;
  }
}

:deep(.el-radio__label) {
  width: 90% !important;
  text-overflow: ellipsis;
  white-space: normal;
  word-wrap: break-word;
  display: inline-block;
  vertical-align: middle;
}
</style>
